%% "Econometrics of the Hodrick-Prescott Filter," Robert de Jong and Neslihan Sakarya (2015)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This program compiles Table 1 and Table 2 (in Appendix 1) of the paper
%% After you run the program, the following results are displayed in the command window:
% (1) A (3x4) table that shows the values of xi calculated for different
% values of the smoothing parameter, lambda, and for different number of
% observations

% (2) A (3x4) table that shows the values of phi calculated for different
% values of the smoothing parameter, lambda, and for different number of
% observations
%%
clear all;
close all;
clc;

T=[25, 50, 100, 1000];
lm=[100, 400, 1600];
dlt=zeros(size(lm,2),size(T,2));
eta=zeros(size(lm,2),size(T,2));
for k=1:size(lm,2);
for i=1:size(T,2);
 



for j=1:T(i);

    dlt(k,i)=dlt(k,i)+(sin(pi*(j-1)/(2*T(i)))^4*cos(pi*(j-1)/(2*T(i)))^2*(1+16*lm(k)*sin(pi*(j-1)/(2*T(i)))^4)^(-1));

    
eta(k,i)=eta(k,i)+(sin(pi*(j-1)/(2*T(i)))^4*cos(pi*(j-1)/(2*T(i)))*cos(pi*(j-1)*(T(i)-(1/2))/T(i))*(1+16*lm(k)*sin(pi*(j-1)/(2*T(i)))^4)^(-1));
    
end

dlt(k,i)=(1/T(i))*dlt(k,i);
eta(k,i)=(1/T(i))*eta(k,i);

xi(k,i)=32*lm(k)*(1-32*lm(k)*dlt(k,i))*(1-64*lm(k)*dlt(k,i)+(32*lm(k))^2*(dlt(k,i)^2-eta(k,i)^2))^(-1);
phi(k,i)=(32*lm(k))^2*eta(k,i)*(1-64*lm(k)*dlt(k,i)+(32*lm(k))^2*(dlt(k,i)^2-eta(k,i)^2))^(-1);
 end
end

printmat(xi,'xi', 'lm=100 lm=400 lm=1600', 'T=25 T=50 T=100 T=1000' )
 
printmat(phi,'phi', 'lm=100 lm=400 lm=1600', 'T=25 T=50 T=100 T=1000' )